#!/bin/bash

ver="1.9.1 1.9.2 central"

mozlang(){
base="/releases/l10n-mozilla-$1/"
[[ "$1" == "central" ]] && base="/l10n-central/"

echo -n "" >$1.langs
local i x
for i in $(wget http://hg.mozilla.org$base -q -O - |grep -oP "\"$base.*?/\"" ) ; do
	i=${i//\"}
	i=${i#$base}
	i=${i%%/*}
	x=$(wget http://hg.mozilla.org$base/$i/file/ -q -O - |grep -oP "\".*?\.tar\.bz2\"" )
	x=${x%\"}
	x=${x##*\"}
	x="http://hg.mozilla.org$x"
	[[ "${x%bz2}" != "${x}" ]] && echo "${i//-/_} $x" >>$1.langs
done
}

if [[ -z "$*" ]]; then
	echo "Snapshotting for mozilla l10n (c) mahatma"
	echo "Usage: $0 <version>"
	echo "       $0 {${ver// /|}|all}"
	exit
fi

for i in ${@//all/${ver}}; do
	mozlang $i
done
